package com.gongj.main;

import com.gongj.DefaultListableBeanFactory.Person;
import com.gongj.bean.User;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

public class Main2 {
	//测试BeanFactory中的方法
	public static void main(String[] args) {
		ClassPathResource resource = new ClassPathResource("spring-config-2.xml");
		DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
		reader.loadBeanDefinitions(resource);
		//获取别名获取Bean对象
		System.out.println("person1 = " + factory.getBean("person"));
		System.out.println("person2 = " +factory.getBean("person", Person.class));
		System.out.println("person3 = " + factory.getBean("person", "gongj", "shanghai"));
		System.out.println("person4 = " + factory.getBean(Person.class));
		System.out.println("person5 = " + factory.getBean(Person.class,"gognj"));

		System.out.println("getBeanProvider = " + factory.getBeanProvider(Person.class));

		System.out.println("containsBean = " + factory.containsBean("person"));
		System.out.println("isSingleton = " + factory.isSingleton("person"));
		System.out.println("isPrototype = " + factory.isPrototype("person"));
		System.out.println("isPrototype = " + factory.isTypeMatch("person",Person.class));
		System.out.println("getType = " + factory.getType("person",false));
		System.out.println("getType = " + factory.getType("p",false));

		String[] people = factory.getAliases("person");
		for (String s : people) {
			System.out.println("getAliases = " + s);
		}
		// 根据类型获取beanNames
		String[] beanNamesForType = factory.getBeanNamesForType(User.class);
		for (String s : beanNamesForType) {
			System.out.println(s);
		}
	}
}
